package com.ctshk.app.system.controller;

import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.rpc.system.dto.MainDataFieldDTO;
import com.ctshk.rpc.system.dto.MainDataTableDTO;
import com.ctshk.rpc.system.req.MainDataFieldReq;
import com.ctshk.rpc.system.req.MainDataTableFieldReq;
import com.ctshk.rpc.system.req.MainDataTableQueryReq;
import com.ctshk.rpc.system.req.MainDataTableReq;
import com.ctshk.rpc.system.service.IMainDataFieldService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import com.ctshk.common.web.support.BaseController;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 基础数据字段表 前端控制器
 * </p>
 *
 * @author 谢诗宏
 * @since 2020-12-29
 */
@Api(value="主数据表字段", tags="主数据表字段")
@RestController
@RequestMapping("/main/data/field")
public class MainDataFieldController extends BaseController {

    /**
     * 基础数据字段服务
     */
    @DubboReference
    private IMainDataFieldService mainDataFieldService;


    @ApiOperation(value="查询主数据字段列表", notes="查询主数据字段列表")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "查询字段列表", operDesc = "查询字段列表")
    @PostMapping("/query-list/{tableId}")
    public Result<List<MainDataFieldDTO>> queryList(@PathVariable Long tableId) {
        return Result.success(mainDataFieldService.queryList(tableId));
    }

    @ApiOperation(value="新增主数据表字段", notes="新增主数据表字段")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.ADD, operTitle = "新增主数据表字段", operDesc = "新增主数据表字段")
    @PostMapping("/add")
    public Result add(@RequestBody @Valid MainDataTableFieldReq mainDataTableFieldReq) {
        mainDataFieldService.add(mainDataTableFieldReq, getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value="修改主数据表字段", notes="修改主数据表字段")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.UPDATE, operTitle = "修改主数据表字段", operDesc = "修改主数据表字段")
    @PostMapping("/update-field")
    public Result updateField(@RequestBody @Valid MainDataTableFieldReq mainDataTableFieldReq) {
        mainDataFieldService.updateField(mainDataTableFieldReq, getCurrentUser(getRequest()).getId());
        return Result.success();
    }


}
